package com.example.program.controller;

import com.example.program.pojo.Emp;
import com.example.program.pojo.Result;
import com.example.program.service.EmpService;


import com.example.program.utils.JWT;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;

@RestController
public class LoginController {
@Autowired
    private EmpService empService;
@PostMapping("/login")
public Result login(@RequestBody Emp emp)
{
   Emp e= empService.login(emp);

   if(e!=null)
   {
       Map<String,Object> claims=new HashMap<>();
       claims.put("id",e.getId());
       claims.put("user",e.getName());
       claims.put("name",e.getName());

       String token= JWT.retunJwt(claims);

       return Result.success(token);
   }
    return Result.error("用户名或密码错误");

}

}
